/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.meanzoft.m3d.scene.impl;

import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector3f;
import org.meanzoft.m3d.resource.ResourceManager;
import org.meanzoft.m3d.scene.Renderable;
import org.meanzoft.m3d.scene.SceneNode;
import org.meanzoft.m3d.texture.v2.Texture;

/**
 *
 * @author Meanz
 */
public class Box extends SceneNode implements Renderable {

    private int boxListId;
    public int type;
    
    public Box(float x, float y, float z, int type) {
        this.position = new Vector3f(x, y, z);
        this.type = type;
        boxListId = GL11.glGenLists(1);
        GL11.glNewList(boxListId, GL11.GL_COMPILE);
        {
            GL11.glBegin(GL11.GL_QUADS);
            {
                /** Front Face **/
                vertex(0f, 0f, 0f, 0f, 0f);
                vertex(0f, 1f, 0f, 0f, 1f);
                vertex(1f, 1f, 0f, 1f, 1f);
                vertex(1f, 0f, 0f, 1f, 0f);

                /** Right Face **/
                vertex(1f, 0f, 0f, 0.25f, 0.5f);
                vertex(1f, 1f, 0f, 0.25f, 0f);
                vertex(1f, 1f, -1f, 0.5f, 0f);
                vertex(1f, 0f, -1f, 0.5f, 0.5f);

                /** Back Face **/
                vertex(1f, 0f, -1f, 0.5f, 0.5f);
                vertex(1f, 1f, -1f, 0.5f, 0f);
                vertex(0f, 1f, -1f, 0.75f, 0f);
                vertex(0f, 0f, -1f, 0.75f, 0.5f);

                /** Left Face **/
                vertex(0f, 0f, -1f, 0f, 1f);
                vertex(0f, 1f, -1f, 0f, 0.5f);
                vertex(0f, 1f, 0f, 0.25f, 0.5f);
                vertex(0f, 0f, 0f, 0.25f, 1f);

                /** Bottom Face **/
                vertex(0f, 0f, -1f, 0.25f, 1f);
                vertex(0f, 0f, 0f, 0.25f, 0.5f);
                vertex(1f, 0f, 0f, 0.5f, 0.5f);
                vertex(1f, 0f, -1f, 0.5f, 1f);

                /** Top Face **/
                vertex(0f, 1f, 0f, 0.5f, 1f);
                vertex(0f, 1f, -1f, 0.5f, 0.5f);
                vertex(1f, 1f, -1f, 0.75f, 0.5f);
                vertex(1f, 1f, 0f, 0.75f, 1f);
            }
            GL11.glEnd();
        }
        GL11.glEndList();
    }
    public void render() {
        GL11.glColor3f(1f, 1f, 1f);
        //tex.bind();
        ResourceManager.getManager().getTexture("stone").bind();
        GL11.glCallList(boxListId);
    }

    private void vertex(float x, float y, float z, float texX, float texY) {
        GL11.glTexCoord2f(texX, texY);
        GL11.glVertex3f(x, y, z);
    }
}
